package com.goldcn.user.controller;

import com.goldcn.enums.ErpInterfaceCfgEnum;
import com.goldcn.user.dao.OrganizationalMapper;
import com.goldcn.user.model.Organizational;
import com.goldcn.user.service.ConfigService;
import com.goldcn.user.service.ErpInterfaceService;
import com.goldcn.util.CommonTools;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * Created by Administrator on 2017/5/2.
 */
@Api(value = "ERP对接接口")
@RestController
@RequestMapping(value = "/erp")
public class ErpController {
    @Autowired
    ErpInterfaceService erpInterfaceService;

    @Autowired
    OrganizationalMapper organizationalMapper;

    @Autowired
    ConfigService configService;
    @Autowired
    RestTemplate restTemplate;

//    @ApiOperation(value = "组织架构增加")
//    @RequestMapping(value = "/addOrgizationalErp",method = RequestMethod.GET)
//    public Object addOrgForErp(){
//        return erpInterfaceService.addOrUpdateOrgForErp();
//    }
//
//    @ApiOperation(value = "增加供应商信息")
//    @RequestMapping(value = "/addCompanyInfo",method = RequestMethod.GET)
//    public Object selectRoleByID(){
//        return erpInterfaceService.addOrUpdateCompanyForErp();
//    }
////
    @ApiOperation(value = "初始化组织信息")
    @RequestMapping(value = "/maintenceDataOrg",method = RequestMethod.GET)
    public Object mainOrgInfo(){
        //int i = (int)erpInterfaceService.maintenceDateOrg(1);
        int j = (int)erpInterfaceService.maintenceDateOrg(0);
        if(j==1){
            System.out.println("表示所有组织已经分别抛转不同的公司了");
        }
        return j;
    }
    //companyMainData
    @ApiOperation(value = "初始化公司信息")
    @RequestMapping(value = "/maintenceDataCompany",method = RequestMethod.GET)
    public Object mianCompanyInfo(){
        return erpInterfaceService.companyMainData();
    }

    @ApiOperation(value = "测试更新架构信息")
    @RequestMapping(value = "/testUPdateSDFS",method = RequestMethod.GET)
    public Object testUpdateOrg(){
        if(!configService.isOpenErp()){
            return 0;
        }
        Organizational organizational = organizationalMapper.selectByPrimaryKey(861524721445900288l);
        //System.out.println(erpConfig.getUpdateOrganizational()+"*******");CommonTools.getExtString(restTemplate,ErpInterfaceCfgEnum.ADDOTHERORDER.toString()
        erpInterfaceService.addOrUpdateOrgForErp(organizational,1, CommonTools.getExtString(restTemplate, ErpInterfaceCfgEnum.ACCOUNTCODE.getCode()));
        //System.out.println(erpConfig.getUpdateOrganizational()+"*******");
       // erpInterfaceService.addOrUpdateOrgForErp(organizational,1,CommonTools.getExtString(restTemplate, ErpInterfaceCfgEnum.ACCOUNTELSECODE.getCode()));
        return 1;
    }


//
//    @ApiOperation(value = "测试20000条数据")
//    @RequestMapping(value = "/exportSql",method = RequestMethod.GET)
//    public Object exportSql(){
//        return erpInterfaceService.exportSql(0,"1002");
//    }



}
